#ifndef FILEVIEW_H
#define FILEVIEW_H

#include <QWidget>
#include <QFileSystemModel>
#include <QUndoStack>
#include <QUndoCommand>

namespace Ui {
class FileView;
}

class FileView : public QWidget
{
    Q_OBJECT

public:
    explicit FileView(QWidget *parent = nullptr);
    void showEvent(QShowEvent *);
    void keyPressEvent(QKeyEvent* e);
    ~FileView();
signals:
    void PathChanged(const QString& path);
    void AddToPlaylist(QMimeData* data);

private slots:
    void ChangeFilePath(const QString& new_path);
    void ItemActivated(const QModelIndex& index);
    void ItemDoubleClick(const QModelIndex& index);

protected:
    void ChangeFilePathWithoutUndo(const QString& new_path);

private:
    class UndoCommand : public QUndoCommand {
     public:
      UndoCommand(FileView* view, const QString& new_path);

      QString undo_path() const { return old_state_.path; }

      void undo();
      void redo();

     private:
      struct State {
        State() : scroll_pos(-1) {}

        QString path;
        QModelIndex index;
        int scroll_pos;
      };

      FileView* view_;
      State old_state_;
      State new_state_;
    };

    Ui::FileView *ui;

    QFileSystemModel * model_;
    QUndoStack* undo_stack_;

};

#endif // FILEVIEW_H
